From 85b2cf8f063e1d282a1e1554afde5d41bf8d8e58 Mon Sep 17 00:00:00 2001 From: Keir Fraser Date: Fri, 30 Mar 2007 19:02:40 +0100 Subject: [PATCH] hvm svm: Some code cleanups. Signed-off-by: Keir Fraser --- xen/arch/x86/hvm/svm/svm.c | 29 +++++++++++------------------ xen/arch/x86/mm/paging.c | 15 +++++++-------- 2 files changed, 18 insertions(+), 26 deletions(-) diff --git a/xen/arch/x86/hvm/svm/svm.c b/xen/arch/x86/hvm/svm/svm.c index 99f3e87713..733068e487 100644 --- a/xen/arch/x86/hvm/svm/svm.c +++ b/xen/arch/x86/hvm/svm/svm.c @@ -70,7 +70,6 @@ u64 root_vmcb_pa[NR_CPUS] __read_mostly; /* hardware assisted paging bits */ extern int opt_hap_enabled; -extern int hap_capable_system; static inline void svm_inject_exception(struct vcpu *v, int trap, int ev, int error_code) @@ -920,16 +919,13 @@ void svm_npt_detect(void) { u32 eax, ebx, ecx, edx; - /* check CPUID for nested paging support */ + /* Check CPUID for nested paging support. */ cpuid(0x8000000A, &eax, &ebx, &ecx, &edx); - if ( edx & 0x01 ) /* nested paging */ - { - hap_capable_system = 1; - } - else if ( opt_hap_enabled ) + + if ( !(edx & 1) && opt_hap_enabled ) { - printk(" nested paging is not supported by this CPU.\n"); - hap_capable_system = 0; /* no nested paging, we disable flag. */ + printk("SVM: Nested paging is not supported by this CPU.\n"); + opt_hap_enabled = 0; } } @@ -944,7 +940,7 @@ int start_svm(void) ecx = cpuid_ecx(0x80000001); boot_cpu_data.x86_capability[5] = ecx; - if (!(test_bit(X86_FEATURE_SVME, &boot_cpu_data.x86_capability))) + if ( !(test_bit(X86_FEATURE_SVME, &boot_cpu_data.x86_capability)) ) return 0; /* check whether SVM feature is disabled in BIOS */ @@ -955,13 +951,13 @@ int start_svm(void) return 0; } - if ( (hsa[cpu] == NULL) && ((hsa[cpu] = alloc_host_save_area()) == NULL) ) + if ( ((hsa[cpu] = alloc_host_save_area()) == NULL) || + ((root_vmcb[cpu] = alloc_vmcb()) == NULL) ) return 0; - + rdmsr(MSR_EFER, eax, edx); eax |= EFER_SVME; wrmsr(MSR_EFER, eax, edx); - printk("AMD SVM Extension is enabled for cpu %d.\n", cpu ); svm_npt_detect(); @@ -970,12 +966,9 @@ int start_svm(void) phys_hsa_lo = (u32) phys_hsa; phys_hsa_hi = (u32) (phys_hsa >> 32); wrmsr(MSR_K8_VM_HSAVE_PA, phys_hsa_lo, phys_hsa_hi); - - if ( (root_vmcb[cpu] == NULL) && - ((root_vmcb[cpu] = alloc_vmcb()) == NULL) ) - return 0; - root_vmcb_pa[cpu] = virt_to_maddr(root_vmcb[cpu]); + root_vmcb_pa[cpu] = virt_to_maddr(root_vmcb[cpu]); + if ( cpu != 0 ) return 1; diff --git a/xen/arch/x86/mm/paging.c b/xen/arch/x86/mm/paging.c index 18805c92e5..b6b148bbdc 100644 --- a/xen/arch/x86/mm/paging.c +++ b/xen/arch/x86/mm/paging.c @@ -27,9 +27,8 @@ #include /* Xen command-line option to enable hardware-assisted paging */ -int opt_hap_enabled = 0; +int opt_hap_enabled; boolean_param("hap", opt_hap_enabled); -int hap_capable_system = 0; /* Printouts */ #define PAGING_PRINTK(_f, _a...) \ @@ -49,14 +48,14 @@ void paging_domain_init(struct domain *d) p2m_init(d); shadow_domain_init(d); - if ( opt_hap_enabled && hap_capable_system && is_hvm_domain(d) ) + if ( opt_hap_enabled && is_hvm_domain(d) ) hap_domain_init(d); } /* vcpu paging struct initialization goes here */ void paging_vcpu_init(struct vcpu *v) { - if ( opt_hap_enabled && hap_capable_system && is_hvm_vcpu(v) ) + if ( opt_hap_enabled && is_hvm_vcpu(v) ) hap_vcpu_init(v); else shadow_vcpu_init(v); @@ -67,7 +66,7 @@ int paging_domctl(struct domain *d, xen_domctl_shadow_op_t *sc, XEN_GUEST_HANDLE(void) u_domctl) { /* Here, dispatch domctl to the appropriate paging code */ - if ( opt_hap_enabled && hap_capable_system && is_hvm_domain(d) ) + if ( opt_hap_enabled && is_hvm_domain(d) ) return hap_domctl(d, sc, u_domctl); else return shadow_domctl(d, sc, u_domctl); @@ -76,7 +75,7 @@ int paging_domctl(struct domain *d, xen_domctl_shadow_op_t *sc, /* Call when destroying a domain */ void paging_teardown(struct domain *d) { - if ( opt_hap_enabled && hap_capable_system && is_hvm_domain(d) ) + if ( opt_hap_enabled && is_hvm_domain(d) ) hap_teardown(d); else shadow_teardown(d); @@ -85,7 +84,7 @@ void paging_teardown(struct domain *d) /* Call once all of the references to the domain have gone away */ void paging_final_teardown(struct domain *d) { - if ( opt_hap_enabled && hap_capable_system && is_hvm_domain(d) ) + if ( opt_hap_enabled && is_hvm_domain(d) ) hap_final_teardown(d); else shadow_final_teardown(d); @@ -95,7 +94,7 @@ void paging_final_teardown(struct domain *d) * creation. */ int paging_enable(struct domain *d, u32 mode) { - if ( opt_hap_enabled && hap_capable_system && is_hvm_domain(d) ) + if ( opt_hap_enabled && is_hvm_domain(d) ) return hap_enable(d, mode | PG_HAP_enable); else return shadow_enable(d, mode | PG_SH_enable); -- 2.30.2